﻿using System;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;
using System.Data;
using Besture.UI.ClassHelper;
using DevExpress.Web.ASPxGridView;

namespace Besture.UI
{
    public partial class CtripOrderSet : BasePage
    {
        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            //页面加载
            InitPage();
            //编辑编号
            InitData(ID);
            AspxGridViewHelper.InitAspxGridView(grid);
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {
            InitPage();
        }

        /// <summary>
        /// 页面加载
        /// </summary>
        public void InitPage()
        {
            var dac = new OrderLogDac();
            grid.DataSource = dac.GetDataTable();
            grid.DataBind();
        }

        /// <summary>
        /// AspxGridView回发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridCustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            if (e.Parameters == "Refresh")
                grid.DataBind();
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        /// <param name="id">编号</param>
        protected void InitData(int id)
        {
            if (id == 0) return;

            var dac = new OrderDac();
            var model = dac.GetModel(id);
			if(model==null) return;

            /*txtOrderNo.Text = model.OrderNo.ToString();
			txtUserID.Text = model.UserID.ToString();
			txtHotelsID.Text = model.HotelsID.ToString();
			txtRoomID.Text = model.RoomID.ToString();
			txtCheckDate.Text =  Convert.ToDateTime(model.CheckDate).ToString("yyyy-MM-dd");
			txtDepartureDate.Text =  Convert.ToDateTime(model.DepartureDate).ToString("yyyy-MM-dd");
			txtRoomQuantity.Text = model.RoomQuantity.ToString();
			txtLatestTime.Text =  Convert.ToDateTime(model.LatestTime).ToString("yyyy-MM-dd");
			txtContactName.Text = model.ContactName.ToString();
			txtContactPhone.Text = model.ContactPhone.ToString();
			txtContactEmail.Text = model.ContactEmail.ToString();
			txtOtherClaims.Text = model.OtherClaims.ToString();
			txtOtherClaimsRemark.Text = model.OtherClaimsRemark.ToString();
			txtReservationNumber.Text = model.ReservationNumber.ToString();
			txtCopePrice.Text = model.CopePrice.ToString();
			txtDeductiblePrice.Text = model.DeductiblePrice.ToString();
			txtNightNumberPrice.Text = model.NightNumberPrice.ToString();
			txtPreferentialPrice.Text = model.PreferentialPrice.ToString();
			txtActuallyPaidPrice.Text = model.ActuallyPaidPrice.ToString();
			txtOrderStatus.Text = model.OrderStatus.ToString();
			txtPayMethod.Text = model.PayMethod.ToString();
			txtRefundTime.Text =  Convert.ToDateTime(model.RefundTime).ToString("yyyy-MM-dd");
			txtPayTime.Text =  Convert.ToDateTime(model.PayTime).ToString("yyyy-MM-dd");
			txtCreateTime.Text =  Convert.ToDateTime(model.CreateTime).ToString("yyyy-MM-dd");
			txtOrderNo.Text = model.OrderNo.ToString();
			txtUserID.Text = model.UserID.ToString();
			txtHotelsID.Text = model.HotelsID.ToString();
			txtRoomID.Text = model.RoomID.ToString();
			txtCheckDate.Text =  Convert.ToDateTime(model.CheckDate).ToString("yyyy-MM-dd");
			txtDepartureDate.Text =  Convert.ToDateTime(model.DepartureDate).ToString("yyyy-MM-dd");
			txtRoomQuantity.Text = model.RoomQuantity.ToString();
			txtLatestTime.Text =  Convert.ToDateTime(model.LatestTime).ToString("yyyy-MM-dd");
			txtContactName.Text = model.ContactName.ToString();
			txtContactPhone.Text = model.ContactPhone.ToString();
			txtContactEmail.Text = model.ContactEmail.ToString();
			txtOtherClaims.Text = model.OtherClaims.ToString();
			txtOtherClaimsRemark.Text = model.OtherClaimsRemark.ToString();
			txtReservationNumber.Text = model.ReservationNumber.ToString();
			txtCopePrice.Text = model.CopePrice.ToString();
			txtDeductiblePrice.Text = model.DeductiblePrice.ToString();
			txtNightNumberPrice.Text = model.NightNumberPrice.ToString();
			txtPreferentialPrice.Text = model.PreferentialPrice.ToString();
			txtActuallyPaidPrice.Text = model.ActuallyPaidPrice.ToString();
			txtOrderStatus.Text = model.OrderStatus.ToString();
			txtPayMethod.Text = model.PayMethod.ToString();
			txtRefundTime.Text =  Convert.ToDateTime(model.RefundTime).ToString("yyyy-MM-dd");
			txtPayTime.Text =  Convert.ToDateTime(model.PayTime).ToString("yyyy-MM-dd");
			txtSortID.SortValue = model.SortID != 0 ? model.SortID : 0;
			txtIsDeleted.Text = model.IsDeleted.ToString();
			txtCreated.Text = model.Created.ToString();
			txtCreateTime.Text =  Convert.ToDateTime(model.CreateTime).ToString("yyyy-MM-dd");
			txtUpdated.Text = model.Updated.ToString();
			txtUpdateTime.Text =  Convert.ToDateTime(model.UpdateTime).ToString("yyyy-MM-dd");*/

			
        }
        #endregion

        #region 保存

        protected void BtnSubmitClick(object sender, EventArgs eventArgs)
        {
            var dac = new OrderDac();
            OrderModel model=null;
            var baseDac = new BaseDac<OrderModel>();
            //添加
            if (!EditPage)
            {
                model = new OrderModel();
               /* model.OrderNo = txtOrderNo.Text.Trim();
				model.UserID = txtUserID.Text.Trim();
				model.HotelsID = txtHotelsID.Text.Trim();
				model.RoomID = txtRoomID.Text.Trim();
				model.CheckDate = txtCheckDate.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtCheckDate.Text.Trim());
				model.DepartureDate = txtDepartureDate.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtDepartureDate.Text.Trim());
				model.RoomQuantity = txtRoomQuantity.Text.Trim();
				model.LatestTime = txtLatestTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtLatestTime.Text.Trim());
				model.ContactName = txtContactName.Text.Trim();
				model.ContactPhone = txtContactPhone.Text.Trim();
				model.ContactEmail = txtContactEmail.Text.Trim();
				model.OtherClaims = txtOtherClaims.Text.Trim();
				model.OtherClaimsRemark = txtOtherClaimsRemark.Text.Trim();
				model.ReservationNumber = txtReservationNumber.Text.Trim();
				model.CopePrice = txtCopePrice.Text.Trim();
				model.DeductiblePrice = txtDeductiblePrice.Text.Trim();
				model.NightNumberPrice = txtNightNumberPrice.Text.Trim();
				model.PreferentialPrice = txtPreferentialPrice.Text.Trim();
				model.ActuallyPaidPrice = txtActuallyPaidPrice.Text.Trim();
				model.OrderStatus = txtOrderStatus.Text.Trim();
				model.PayMethod = txtPayMethod.Text.Trim();
				model.RefundTime = txtRefundTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtRefundTime.Text.Trim());
				model.PayTime = txtPayTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtPayTime.Text.Trim());
				model.CreateTime = txtCreateTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtCreateTime.Text.Trim());
				model.OrderNo = txtOrderNo.Text.Trim();
				model.UserID = txtUserID.Text.Trim();
				model.HotelsID = txtHotelsID.Text.Trim();
				model.RoomID = txtRoomID.Text.Trim();
				model.CheckDate = txtCheckDate.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtCheckDate.Text.Trim());
				model.DepartureDate = txtDepartureDate.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtDepartureDate.Text.Trim());
				model.RoomQuantity = txtRoomQuantity.Text.Trim();
				model.LatestTime = txtLatestTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtLatestTime.Text.Trim());
				model.ContactName = txtContactName.Text.Trim();
				model.ContactPhone = txtContactPhone.Text.Trim();
				model.ContactEmail = txtContactEmail.Text.Trim();
				model.OtherClaims = txtOtherClaims.Text.Trim();
				model.OtherClaimsRemark = txtOtherClaimsRemark.Text.Trim();
				model.ReservationNumber = txtReservationNumber.Text.Trim();
				model.CopePrice = txtCopePrice.Text.Trim();
				model.DeductiblePrice = txtDeductiblePrice.Text.Trim();
				model.NightNumberPrice = txtNightNumberPrice.Text.Trim();
				model.PreferentialPrice = txtPreferentialPrice.Text.Trim();
				model.ActuallyPaidPrice = txtActuallyPaidPrice.Text.Trim();
				model.OrderStatus = txtOrderStatus.Text.Trim();
				model.PayMethod = txtPayMethod.Text.Trim();
				model.RefundTime = txtRefundTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtRefundTime.Text.Trim());
				model.PayTime = txtPayTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtPayTime.Text.Trim());
				model.SortID = txtSortID.SortValue != 0 ? txtSortID.SortValue : 0;
				model.IsDeleted = txtIsDeleted.Text.Trim();
				model.Created = txtCreated.Text.Trim();
				model.CreateTime = txtCreateTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtCreateTime.Text.Trim());
				model.Updated = txtUpdated.Text.Trim();
				model.UpdateTime = txtUpdateTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtUpdateTime.Text.Trim());*/

                //加载添加基本数据
                baseDac.LoadAddBaseModel(model);
				

                dac.Add(model);
            }
            //编辑
            else
            {
                model = dac.GetModel(ID);
                /*model.OrderNo = txtOrderNo.Text.Trim();
				model.UserID = txtUserID.Text.Trim();
				model.HotelsID = txtHotelsID.Text.Trim();
				model.RoomID = txtRoomID.Text.Trim();
				model.CheckDate = txtCheckDate.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtCheckDate.Text.Trim());
				model.DepartureDate = txtDepartureDate.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtDepartureDate.Text.Trim());
				model.RoomQuantity = txtRoomQuantity.Text.Trim();
				model.LatestTime = txtLatestTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtLatestTime.Text.Trim());
				model.ContactName = txtContactName.Text.Trim();
				model.ContactPhone = txtContactPhone.Text.Trim();
				model.ContactEmail = txtContactEmail.Text.Trim();
				model.OtherClaims = txtOtherClaims.Text.Trim();
				model.OtherClaimsRemark = txtOtherClaimsRemark.Text.Trim();
				model.ReservationNumber = txtReservationNumber.Text.Trim();
				model.CopePrice = txtCopePrice.Text.Trim();
				model.DeductiblePrice = txtDeductiblePrice.Text.Trim();
				model.NightNumberPrice = txtNightNumberPrice.Text.Trim();
				model.PreferentialPrice = txtPreferentialPrice.Text.Trim();
				model.ActuallyPaidPrice = txtActuallyPaidPrice.Text.Trim();
				model.OrderStatus = txtOrderStatus.Text.Trim();
				model.PayMethod = txtPayMethod.Text.Trim();
				model.RefundTime = txtRefundTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtRefundTime.Text.Trim());
				model.PayTime = txtPayTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtPayTime.Text.Trim());
				model.CreateTime = txtCreateTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtCreateTime.Text.Trim());
				model.OrderNo = txtOrderNo.Text.Trim();
				model.UserID = txtUserID.Text.Trim();
				model.HotelsID = txtHotelsID.Text.Trim();
				model.RoomID = txtRoomID.Text.Trim();
				model.CheckDate = txtCheckDate.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtCheckDate.Text.Trim());
				model.DepartureDate = txtDepartureDate.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtDepartureDate.Text.Trim());
				model.RoomQuantity = txtRoomQuantity.Text.Trim();
				model.LatestTime = txtLatestTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtLatestTime.Text.Trim());
				model.ContactName = txtContactName.Text.Trim();
				model.ContactPhone = txtContactPhone.Text.Trim();
				model.ContactEmail = txtContactEmail.Text.Trim();
				model.OtherClaims = txtOtherClaims.Text.Trim();
				model.OtherClaimsRemark = txtOtherClaimsRemark.Text.Trim();
				model.ReservationNumber = txtReservationNumber.Text.Trim();
				model.CopePrice = txtCopePrice.Text.Trim();
				model.DeductiblePrice = txtDeductiblePrice.Text.Trim();
				model.NightNumberPrice = txtNightNumberPrice.Text.Trim();
				model.PreferentialPrice = txtPreferentialPrice.Text.Trim();
				model.ActuallyPaidPrice = txtActuallyPaidPrice.Text.Trim();
				model.OrderStatus = txtOrderStatus.Text.Trim();
				model.PayMethod = txtPayMethod.Text.Trim();
				model.RefundTime = txtRefundTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtRefundTime.Text.Trim());
				model.PayTime = txtPayTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtPayTime.Text.Trim());
				model.SortID = txtSortID.SortValue != 0 ? txtSortID.SortValue : 0;
				model.IsDeleted = txtIsDeleted.Text.Trim();
				model.Created = txtCreated.Text.Trim();
				model.CreateTime = txtCreateTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtCreateTime.Text.Trim());
				model.Updated = txtUpdated.Text.Trim();
				model.UpdateTime = txtUpdateTime.Text.Trim() == "" ? Convert.ToDateTime("0001/01/01") : Convert.ToDateTime(txtUpdateTime.Text.Trim());*/

                //加载修改基本数据
                baseDac.LoadUpdateBaseModel(model);
				

                dac.Update(model);
            }

            FunHelper.Alert("保存成功", ListUrl());
        }
        #endregion
    }
}